package com.semptian.deye.semptian.analyzer;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.common.io.PathUtils;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.analysis.AbstractIndexAnalyzerProvider;

import java.io.File;
import java.nio.file.Path;

/**
 * @author zww
 * @date 2021/8/12 20:21
 * @desc
 */
public class SemptianAnalyzerProvider extends AbstractIndexAnalyzerProvider<SemptianAnalyzer> {
    private final static Logger LOG = LogManager.getLogger(SemptianAnalyzerProvider.class);
    private final SemptianAnalyzer semptianAnalyzer;

    public SemptianAnalyzerProvider(IndexSettings indexSettings, Environment environment, String name, Settings settings) {
        super(indexSettings, name, settings);
        semptianAnalyzer = new SemptianAnalyzer();
        //设置jieba分词的配置路径信息
        Path configPath = PathUtils.get(new File(SemptianAnalyzer.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getParent()).toAbsolutePath().resolve("jieba_config.properties");
        LOG.info("开始加载配置文件:[{}]", configPath.toAbsolutePath());
    }

    @Override
    public SemptianAnalyzer get() {
        return semptianAnalyzer;
    }
}
